home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
preccx
/
prccx240.lha
/
atexit.c
next >
Wrap
C/C++ Source or Header
|
1993-05-27
|
749b
|
34 lines
typedef void (* atexit_t)(void);
#ifndef ATEXIT_MAX
#define ATEXIT_MAX 32
#endif
#ifndef NULL
#define NULL 0
#endif
int atexit(f)
/* we'll register f in a stack, spawn a continuation process,
* and execute f when it exits, having junked as much of
* ourself as possible in the meantime.
*/
atexit_t f;
{
static atexit_t flist[ATEXIT_MAX];
static int fptr, pid;
if(fptr>=ATEXIT_MAX)
return(1);
flist[fptr++]=f;
switch(pid=vfork()){
case 0: /* we're the child - just continue */
return 0;
default: /* we're the parent*/
waitpid(pid,NULL,0); /* for the child to finish */
flist[--fptr](); /* now clean up */
exit(0);/* and go home happy? */
return 0;
}
}